<%@page import="java.io.File"%>
<%@page import="models.User"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Header</title>
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".followH").click(function(event) {
    	$.post('UserController',{follow: $(this).data('user')}, function(data){
        	$('#topcolumn').load('homeheader.jsp');
        	$('#rightcolumn').load('ContentController');
    	});
	});
    $(".unfollowH").click(function(event) {
    	$.post('UserController',{unfollow: $(this).data('user')}, function(data){
        	$('#topcolumn').load('homeheader.jsp');
            $('#rightcolumn').load('ContentController');
    	});
    	
	});
    $(".addContactH").click(function(event) {
    	$.post('UserController',{addContact: $(this).data('user')},function(data){
        	$('#topcolumn').load('homeheader.jsp');
            $('#rightcolumn').load('ContentController');
    		}
    	);
    	
	});
    $(".deleteContactH").click(function(event) {
    	$.post('UserController',{deleteContact: $(this).data('user')},function(data){
        	$('#topcolumn').load('homeheader.jsp');
            $('#rightcolumn').load('ContentController');
    		}
    	);
	});
    $(".deleteUserH").click(function(event) {
    	$.post('UserController',{deleteUser: $(this).data('user')});
    	$('#wrapper').load('HomeController',{viewUser: $(this).data('usersession')});
	});
    
});
</script>
</head>
<body>
<%
User currentUser = (User)session.getAttribute("currentUser");
%> 
<div id="headerDiv">
<%if (!currentUser.getUser().equals(session.getAttribute("user"))){
if(currentUser.isFollowing()){%>
<div style="float:right; margin-top:20px; margin-right:40px;"><a href="#" data-user="<%=currentUser.getUser()%>" class="unfollowH">Unfollow</a></div>
<%} else { %>
<div style="float:right; margin-top:20px; margin-right:40px"><a href="#" data-user="<%=currentUser.getUser()%>" class="followH">Follow</a></div>
<%} if(currentUser.isContact()){ %>
<div style="float:right; margin-top:20px; margin-right:40px"><a href="#" data-user="<%=currentUser.getUser()%>" class="deleteContactH">Delete contact</a></div>
<%} else { %>
<div style="float:right; margin-top:20px; margin-right:40px"><a href="#" data-user="<%=currentUser.getUser()%>" class="addContactH">Add contact</a></div>
<%} }%>
<%if(session.getAttribute("isAdmin") != null) {%>
<div style="float:right; margin-top:20px; margin-right:40px"><a href="#" data-user="<%=currentUser.getUser()%>" data-usersession="<%= session.getAttribute("user") %>" class="deleteUserH">Eliminar Usuario</a></div>
<%} %>
<div style="float:left">
<%
String path = getServletContext().getRealPath("/etc/img");
File f = new java.io.File(path + "/tweet_" + currentUser.getUser() + ".jpg");
if(f.exists()) {%><img  src="./etc/img/tweet_<%=currentUser.getUser()%>.jpg"/><%} else{ %><img src="./etc/img/tweet_nopic.jpg"/>
<%} %></div>
<div id="userInfo" style="margin-left:70px;">
<%User user;
	 if(currentUser!=null){ 
		 user = (User)session.getAttribute("currentUser"); %>
	<h1><%=user.getName() %></h1><h3><%=user.getEmail() %></h3>
	<%}%>
</div>
	
</div>
</body>
</html>